package com.ruoyi.dm.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.SseEmitterUtils;
import com.ruoyi.dm.domain.*;
import com.ruoyi.dm.mapper.DataManagementMapper;
import com.ruoyi.dm.service.DataManangementService;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.InputStream;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class DataManagementServiceImpl implements DataManangementService {

    @Resource
    private DataManagementMapper dataManagementMapper;


    @Override
    public AjaxResult add(DataManagementParam param) {
        //首先进行数据来源唯一性确定
//        int count = dataManagementMapper.isDataSource(param.getParentId(),param.getDataName(),param.getDataSource());
//        if (count>0){
//            return AjaxResult.warn("当前资料已经存在该数据来源，请重新选择！");
//        }
        //根据数据类型获取对应默认的表结构
        String filePath;
        if (!param.getDataType().equals("nc")){
            filePath = "template/tableStructure.json";
        }else {
            filePath = "template/tableStructure2.json";
        }

        //进行表结构Json添加
//        File file = null;
        String json = "";
        try {
            InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(filePath);
//            file = ResourceUtils.getFile(filePath);
//            json = FileUtils.readFileToString(file, "UTF-8");
              json = IOUtils.toString(inputStream,"UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        param.setTableStructure(json);
        Date date = new Date();
        param.setCreateTime(date);
        //进行数据入库
        dataManagementMapper.add(param);
        return AjaxResult.success("资料新增成功");
    }

    /**
     * 分页查询
     */
    @Override
    public List<DataManagementParam> selectList(DataManagementParam param) {
        return dataManagementMapper.selectList(param);
    }

    /**
     * 编辑资料
     */
    @Override
    public AjaxResult edit(DataManagementParam param) {
        Date date = new Date();
        param.setUpdateTime(date);
        dataManagementMapper.edit(param);
        //判断卫星信息表中是否存在该资料，存在即更新
        Long id = dataManagementMapper.getSatelliteId(param.getId());
        if (id != null && param.getDataType().equals("元数据")){
            //进行卫星信息表信息更新
            dataManagementMapper.editSatelliteInfo(id, param.getDataSource(),null);
        }else if(id != null && param.getDataType().equals("产品数据")) {
            //进行卫星信息删除
            dataManagementMapper.deleteSatelliteInfo(id, null);
        }
        return AjaxResult.success("修改成功");
    }

    /**
     * 删除资料
     */
    @Override
    public AjaxResult delete(List<Long> ids) {
        //根据id获取所有删除资料的id
        List<DataManagementParam> list = dataManagementMapper.getByIds(ids);
        //首先进行表中数据清空 然后进行表删除
        for (DataManagementParam param : list) {
            TableInfoParam tableInfoParam = JSON.parseObject(param.getTableStructure(),TableInfoParam.class);
            if (!StringUtils.isBlank(tableInfoParam.getTableName())){
                //根据文件类型 进行文件删除
                if (!param.getDataType().equals("nc")){
                    //判断是否存在该表
                    int count = dataManagementMapper.isTable((tableInfoParam.getTableName()).toUpperCase());
                    if (count>0){
                        dataManagementMapper.executeSql("TRUNCATE TABLE "+tableInfoParam.getTableName());
                        dataManagementMapper.executeSql("DROP TABLE "+tableInfoParam.getTableName());
                    }
                    count = dataManagementMapper.isTable((tableInfoParam.getTableName()+"_FILE").toUpperCase());
                    if (count>0){
                        dataManagementMapper.executeSql("TRUNCATE TABLE "+tableInfoParam.getTableName()+"_FILE");
                        dataManagementMapper.executeSql("DROP TABLE "+tableInfoParam.getTableName()+"_FILE");
                    }
                    count = dataManagementMapper.isTable((tableInfoParam.getTableName()+"_PRODUCT").toUpperCase());
                    if (count>0){
                        dataManagementMapper.executeSql("TRUNCATE TABLE "+tableInfoParam.getTableName()+"_PRODUCT");
                        dataManagementMapper.executeSql("DROP TABLE "+tableInfoParam.getTableName()+"_PRODUCT");
                    }
                }else{
                    //判断是否存在该表
                    int count = dataManagementMapper.isTable((tableInfoParam.getTableName()).toUpperCase());
                    if(count>0) {
                        dataManagementMapper.executeSql("TRUNCATE TABLE "+tableInfoParam.getTableName());
                        dataManagementMapper.executeSql("DROP TABLE "+tableInfoParam.getTableName());
                    }
                    count = dataManagementMapper.isTable((tableInfoParam.getTableName().toUpperCase()).replaceAll("FILE","PRODUCT"));
                    if(count>0) {
                        dataManagementMapper.executeSql("TRUNCATE TABLE "+tableInfoParam.getTableName().replaceAll("FILE","PRODUCT"));
                        dataManagementMapper.executeSql("DROP TABLE "+tableInfoParam.getTableName().replaceAll("FILE","PRODUCT"));
                    }
                }
                //进行卫星信息表数据更新
                dataManagementMapper.deleteSatelliteInfo(null, tableInfoParam.getTableName());
            }
        }
        //最后进行资料删除
        dataManagementMapper.deleteByIds(ids);
        return AjaxResult.success("资料删除成功!");
    }

    @Override
    public void offChannel() {
        //获取用户信息
        LoginUser loginUser = SecurityUtils.getLoginUser();
        //关闭该用户下所有通道
        SseEmitterUtils.removeByUser(loginUser.getUsername());

    }

    @Override
    public AjaxResult insertFuture(List<String> indexs) {
        for (String str : indexs) {
            List<Map<String, Object>> list = dataManagementMapper.getIndexData("SWDATA_OBS_"+str,"2022-01-01 00:00:00","2022-12-31 23:59:59");
            for (Map<String, Object> map :list) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(DateUtils.convertString2Date("yyyy-MM-dd HH:mm:ss", map.get("DATETIME")+""));
                calendar.add(Calendar.YEAR, 2);
                map.put("DATETIME", calendar.getTime());
                dataManagementMapper.insertFuture("SWDATA_FUTURE_"+str,calendar.getTime(),Float.valueOf(map.get("Y107")+""));
            }
        }
        return null;
    }

    @Override
    public AjaxResult getInfo(Long dataId) {
        //根据资料id获取表结构信息
        DataManagementParam dataManagementParam = dataManagementMapper.getInfo(dataId);
        TableInfoParam tableInfoParam = JSON.parseObject(dataManagementParam.getTableStructure(),TableInfoParam.class);
        //判断是否存在该表
        int count = dataManagementMapper.isTable((tableInfoParam.getTableName()).toUpperCase());
        //查看是否存在表
        int isData = 0;
        if (count>0){
            //查看表中是否存在数据,
            isData = dataManagementMapper.isData(tableInfoParam.getTableName());
            if (isData>0){
                isData=1;
            }
        }
        tableInfoParam.setColumnList(null);
        tableInfoParam.setIndexList(null);
        tableInfoParam.setIsData(isData);
        return AjaxResult.success("获取成功",tableInfoParam);
    }

    @Override
    public AjaxResult createTable(Long dataId) {
        //首先根据资料id获取表结构信息
        DataManagementParam dataManagementParam = dataManagementMapper.getInfo(dataId);
        TableInfoParam tableInfoParam = JSON.parseObject(dataManagementParam.getTableStructure(),TableInfoParam.class);
        //首先是否存在旧表,如果为首次创建，则直接进行表结构创建
        if (StringUtils.isBlank(dataManagementParam.getOldTable())){
            createTableStructure(tableInfoParam,dataManagementParam.getDataType());
            if (!dataManagementParam.getDataUse().equals("产品数据")){
                //进行卫星信息表更新
                dataManagementMapper.saveSatelliteInfo(dataManagementParam.getDataSource(),tableInfoParam.getTableName());
            }
        }else{
            //判断此次表名与之前的旧表一致
            if (dataManagementParam.getOldTable().equals(tableInfoParam.getTableName())){
                //如果存在表则进一步查看表中是否存在数据
                int isData = 0;
                if(!StringUtils.isBlank(tableInfoParam.getTableName())){
                    //查看表中是否存在数据,
                    isData = dataManagementMapper.isData(tableInfoParam.getTableName());
                    if (isData>0){
                        isData=1;
                    }
                }
                tableInfoParam.setIsData(isData);
                //查看表中是否存在数据,存在数据则为进行表结构更新,否则进行表删除重建
                if (tableInfoParam.getIsData()>0){
                    //进行表结构修改
                    alterTableStructure(tableInfoParam);
                }else{
                    //进行表删除
                    dropTableStructure(tableInfoParam.getTableName(),dataManagementParam.getDataType());
                    //进行表结构创建
                    createTableStructure(tableInfoParam,dataManagementParam.getDataType());
                    //进行卫星信息
                }
            }else {
                //否则进行旧表删除
                dropTableStructure(dataManagementParam.getOldTable(),dataManagementParam.getDataType());
                //进行表结构创建
                createTableStructure(tableInfoParam,dataManagementParam.getDataType());
                //判断卫星信息表中是否存在该资料，存在即更新
                Long id = dataManagementMapper.getSatelliteId(dataId);
                dataManagementMapper.editSatelliteInfo(id,null,tableInfoParam.getTableName());
            }
        }
        //进行表结构信息更新
        DataManagementParam param = new DataManagementParam();
        param.setId(dataId);
        param.setTableStructure(JSON.toJSONString(tableInfoParam));
        //表结构信息保存
        param.setOldTable(tableInfoParam.getTableName());
        dataManagementMapper.saveTable(param);
        return AjaxResult.success("表结构创建成功!");
    }

    @Override
    public AjaxResult isTable(Long dataId) {
        DataManagementParam dataManagementParam = dataManagementMapper.getInfo(dataId);
        TableInfoParam tableInfoParam = JSON.parseObject(dataManagementParam.getTableStructure(),TableInfoParam.class);
        if (StringUtils.isBlank(tableInfoParam.getTableName())){
            return AjaxResult.success("请先进行表结构信息保存",0);
        }else {
            //判断是否存在该表
            int count = dataManagementMapper.isTable((tableInfoParam.getTableName()).toUpperCase());
            int count2 = 0;
            //判断是否存在旧表
            if (!StringUtils.isBlank(dataManagementParam.getOldTable())){
                count2 = dataManagementMapper.isTable((dataManagementParam.getOldTable()).toUpperCase());
            }
            if (count+count2>0){
                return AjaxResult.success("该表已经存在!是否继续当前操作",2);
            }else{
                return AjaxResult.success("是否进行表结构创建",1);
            }
        }
    }

    @Override
    public AjaxResult saveTable(DataManagementParam param) {
        DataManagementParam dataManagementParam = dataManagementMapper.getInfo(param.getId());
        TableInfoParam tableInfoParam = JSON.parseObject(param.getTableStructure(),TableInfoParam.class);

        //进行表结构信息更新
        if (dataManagementParam.getDataType().equals("nc") && !(tableInfoParam.getTableName().toUpperCase()).contains("FILE")){
            tableInfoParam.setTableName(tableInfoParam.getTableName()+"_FILE");
        }
//        //判断表是否存在，存在则进行提示
//        int count = dataManagementMapper.isTable((tableInfoParam.getTableName()).toUpperCase());
//        if (count>0){
//            return AjaxResult.warn("该表已经存在，请重新输入表名！");
//        }
        param.setTableStructure(JSON.toJSONString(tableInfoParam));
        dataManagementMapper.saveTable(param);
        return AjaxResult.success("保存成功!");
    }
    /**
     * 创建表
     */
    public void createTableStructure(TableInfoParam param,String dataType) {
//        if (dataType.equals("nc")){
//            param.setTableName(param.getTableName()+"_file");
//        }
        List<TableStructureParam> tableStructureParamList = param.getTableStructure();
        //进行表结构内容拼接
        StringBuilder stringBuilder = new StringBuilder("create table "+param.getTableName()+"(");
        String isPkName = "";
        boolean isIncrement = false;
        for (TableStructureParam tableStructure:tableStructureParamList) {
            //获取字段含义
//            commentBuilder.append("COMMENT ON COLUMN "+param.getTableName()+"."+tableStructure.getColumnName()+" is "+"'"+tableStructure.getDescription()+"';");
            stringBuilder.append(tableStructure.getColumnName()).append(" ");
            stringBuilder.append(tableStructure.getDataType()).append(" ");
            //是否为浮点型
            if(tableStructure.getScale()!=null){
                //是否存在标度
                stringBuilder.append("(").append(tableStructure.getLength()).append(",").append(tableStructure.getScale()).append(") ");
            }else if (tableStructure.getLength()!=null){
                stringBuilder.append("(").append(tableStructure.getLength()).append(") ");
            }
            if(tableStructure.getIsPk()==1){
                isPkName = tableStructure.getColumnName();
            }
            //当存在自增列
            if (tableStructure.getIsIncrement()==1) {
                isIncrement = true;
                stringBuilder.append("not null auto_increment,");
            }else {
                stringBuilder.append("default ").append(tableStructure.getDefaults()).append(",");
            }
        }
        //判断是否包含主键
        if (!StringUtils.isBlank(isPkName)){
            stringBuilder.append("primary key (").append(isPkName).append("));");
        } else {
            stringBuilder.deleteCharAt(stringBuilder.length() - 1);
            stringBuilder.append(");");
        }
        //存在自增列时则不能创建分区
        if (!isIncrement){
            //判断是否存在分区
            if (param.getIsPartition()==1 && param.getPartitionList()!=null && param.getPartitionList().size()>0){
                stringBuilder.deleteCharAt(stringBuilder.length() - 1);
                List<TablePartitionParam> partitionList = param.getPartitionList();
                for (TablePartitionParam partitionParam : partitionList) {
                    stringBuilder.append("PARTITION BY RANGE(").append(partitionParam.getPartitionName()).append(")");
                    stringBuilder.append("INTERVAL(NUMTOYMINTERVAL(").append(partitionParam.getInterval()).append(",'").append(partitionParam.getType()).append("'))(");
                    stringBuilder.append("PARTITION  PARTITION2000  VALUES LESS THAN('").append(DateUtils.convertDate2String("yyyy-MM-dd HH:mm:ss",partitionParam.getMinTime()));
                    stringBuilder.append("'));");
                }
            }
        }
        //执行sql
        dataManagementMapper.executeSql(stringBuilder.toString());
        //给表添加说明
        dataManagementMapper.executeSql("COMMENT ON TABLE "+param.getTableName()+" is "+"'"+param.getTableDescription()+"'");
        //进行注释添加
        for (TableStructureParam tableStructureParam:tableStructureParamList) {
            String comment = "COMMENT ON COLUMN "+param.getTableName()+"."+tableStructureParam.getColumnName()+" is "+"'"+tableStructureParam.getDescription()+"'";
            dataManagementMapper.executeSql(comment);
        }
        //创建索引
        alterIndex(param);
        if (dataType.equals("nc")){
            //创建文件产品索引表
            createFileIndex(param.getTableName().toUpperCase().replaceAll("FILE","PRODUCT"),param.getTableDescription());
            return;
        }
        //创建文件索引表
        createFileIndex(param.getTableName()+"_FILE",param.getTableDescription());
        //创建文件产品索引表
        createFileIndex(param.getTableName()+"_PRODUCT",param.getTableDescription());
    }
//    /**
//     * 创建表
//     * @param param
//     * @return
//     */
//    public void createTableStructure(TableInfoParam param,String dataType) {
//        List<TableStructureParam> tableStructureParamList = param.getTableStructure();
//        //进行表结构内容拼接
//        StringBuilder stringBuilder = new StringBuilder("create table "+param.getTableName()+"(");
//        StringBuilder indexBuilder = new StringBuilder();
//        String isPkName = "";
//        for (TableStructureParam tableStructure:tableStructureParamList) {
//            stringBuilder.append(tableStructure.getColumnName()+" ");
//            stringBuilder.append(tableStructure.getDataType()+" ");
//            //是否为浮点型
//            if(tableStructure.getScale()!=null){
//                //是否存在标度
//                stringBuilder.append("("+tableStructure.getLength()+","+tableStructure.getScale()+") ");
//            }else if (tableStructure.getLength()!=null){
//                stringBuilder.append("("+tableStructure.getLength()+") ");
//            }
//            if(tableStructure.getIsPk()==1){
//                stringBuilder.append("not null auto_increment ");
//                isPkName = tableStructure.getColumnName();
//            }else {
//                stringBuilder.append("default "+tableStructure.getDefaults());
//            }
//            stringBuilder.append(" comment '"+tableStructure.getDescription()+"',");
//        }
//        stringBuilder = stringBuilder.deleteCharAt(stringBuilder.length()-1);
//        //判断是否包含主键
//        if (!StringUtils.isBlank(isPkName)){
//            stringBuilder.append(",primary key ("+isPkName+"));");
//        }
//
//        //进行注释添加
//        stringBuilder.append(commentBuilder);;
//        //执行sql
//        dataManagementMapper.executeSql(stringBuilder.toString());
//        //创建索引
//        alterIndex(param);
//        if (dataType.equals("nc")){
//            return;
//        }
//        //创建文件索引表
//        createFileIndex(param.getTableName()+"_file");
//        //创建文件产品索引表
//        createFileIndex(param.getTableName()+"_product");
//    }
    /**
     * 创建文件索引表
     */
    private void createFileIndex(String tableName, String description){
        //进行表结构内容拼接
        StringBuilder stringBuilder = new StringBuilder("create table "+tableName+"(");
        stringBuilder.append("id bigint not null auto_increment COMMENT 'id',file_name varchar(200) default null COMMENT '文件名',file_path varchar(2000) default null COMMENT '文件路径',file_size varchar(50) default null COMMENT '文件大小'," +
                "file_type varchar(20) default null COMMENT '文件类型',or_file_name varchar(20) default null COMMENT '原始文件名称',data_source varchar(20) default null COMMENT '数据来源',start_time timestamp COMMENT '数据开始时间',end_time timestamp COMMENT '数据结束时间',frequency varchar(20) default null COMMENT '数据频次',create_time timestamp COMMENT '创建时间',update_time timestamp COMMENT '更新时间',primary key (id));");
        //执行sql
        dataManagementMapper.executeSql(stringBuilder.toString());
        if (tableName.toUpperCase().contains("FILE")){
            dataManagementMapper.executeSql("COMMENT ON TABLE "+tableName+" is "+"'"+description+"文件表'");
        }else{
            dataManagementMapper.executeSql("COMMENT ON TABLE "+tableName+" is "+"'"+description+"产品表'");

        }
    }

//    /**
//     * 创建文件索引表
//     * @param tableName
//     */
//    private void createFileIndex(String tableName){
//        //进行表结构内容拼接
//        StringBuilder stringBuilder = new StringBuilder("create table "+tableName+"(");
//        stringBuilder.append("id bigint not null auto_increment,file_name varchar(200) default null,file_path varchar(2000) default null,file_size varchar(50) default null," +
//                "file_type varchar(20) default null,data_time timestamp,create_time timestamp,update_time timestamp,primary key (id));");
//        stringBuilder.append("COMMENT ON COLUMN "+tableName+".id is 'id';COMMENT ON COLUMN "+tableName+".file_name is '文件名';" +
//                "COMMENT ON COLUMN "+tableName+".file_path is '文件路径';COMMENT ON COLUMN "+tableName+".file_size is '文件大小';" +
//                "COMMENT ON COLUMN "+tableName+".file_type is '文件类型';COMMENT ON COLUMN "+tableName+".create_time is '创建时间';" +
//                "COMMENT ON COLUMN "+tableName+".data_time is '资料时间';" +
//                "COMMENT ON COLUMN "+tableName+".update_time is '更新时间';COMMENT ON TABLE "+tableName+" is '文件产品表';");
//        //执行sql
//        dataManagementMapper.executeSql(stringBuilder.toString());
//    }

    private void alterTableStructure(TableInfoParam param){
        StringBuilder stringBuilder = new StringBuilder();
        //表结构修改
        for (TableStructureParam tableStructure:param.getTableStructure()) {
            //判断是否为新增字段
            if (param.getColumnList()!=null && param.getColumnList().size()>0 && !param.getColumnList().contains(tableStructure.getColumnName())){
                stringBuilder.append("ALTER TABLE ");
                stringBuilder.append(param.getTableName());
                stringBuilder.append(" ADD ");
                stringBuilder.append(tableStructure.getColumnName());
                stringBuilder.append(" ").append(tableStructure.getDataType()).append(" ");
                //是否为浮点型
                if(tableStructure.getScale()!=null){
                    //是否存在标度
                    stringBuilder.append("(").append(tableStructure.getLength()).append(",").append(tableStructure.getScale()).append(") ");
                }else if (tableStructure.getLength()!=null){
                    stringBuilder.append("(").append(tableStructure.getLength()).append(") ");
                }
                stringBuilder.append("default ").append(tableStructure.getDefaults()).append(";");
                dataManagementMapper.executeSql(stringBuilder.toString());
                //添加注释
                String comment = "COMMENT ON COLUMN "+param.getTableName()+"."+tableStructure.getColumnName()+" is "+"'"+tableStructure.getDescription()+"'";
                dataManagementMapper.executeSql(comment);
            }
        }
//        List<String> oldList = new ArrayList<>();
//        List<String> newList = new ArrayList<>();

        //索引修改
        alterIndex(param);
//        // 找出oldList中存在而newList中不存在的元素
//        List<String> difference1 = oldList.stream()
//                .filter(e -> !newList.contains(e))
//                .collect(Collectors.toList());
//
//        // 找出newList中存在而oldList中不存在的元素
//        List<String> difference2 = newList.stream()
//                .filter(e -> !oldList.contains(e))
//                .collect(Collectors.toList());
    }
    private void dropTableStructure(String tableName,String dataType){
        String dropSql = "DROP TABLE "+tableName+";";
        dataManagementMapper.executeSql(dropSql);
        if (!dataType.equals("nc")){
            String dropSql1 = "DROP TABLE "+tableName+"_FILE;";
            dataManagementMapper.executeSql(dropSql1);
            String dropSql2 ="DROP TABLE "+tableName+"_PRODUCT;";
            dataManagementMapper.executeSql(dropSql2);
        }else{
            String dropSql2 ="DROP TABLE "+tableName.toUpperCase().replaceAll("FILE","PRODUCT");
            dataManagementMapper.executeSql(dropSql2);
        }
    }

    private void alterIndex(TableInfoParam param){
        //遍历原索引集合
        if (param.getIndexList()!=null && param.getIndexList().size()>0){
            StringBuilder oldIndexBuilder = new StringBuilder("DROP INDEX ");
            boolean flag = false;
            for (TableIndexParam oldIndexParam: param.getIndexList()) {
                //判断索引是否存在
                int count = dataManagementMapper.isIndex("PIESAT_DGDQ_"+param.getTableName()+"_"+oldIndexParam.getIndexName().toUpperCase());
                if (count>0){
                    oldIndexBuilder.toString();
                    oldIndexBuilder.append(oldIndexParam.getIndexName()).append(",");
                    flag = true;
                }

            }
            String oldIndex = oldIndexBuilder.toString();
            oldIndex = oldIndex.substring(0,oldIndex.length()-1)+";";
            //删除索引
            if (flag){
                dataManagementMapper.executeSql(oldIndex);
            }
        }
        //遍历新索引集合
        if (param.getTableIndex()!=null && param.getTableIndex().size()>0){
            //拼接创建索引语句
            for (TableIndexParam indexParam :param.getTableIndex()) {
                StringBuilder indexBuilder = new StringBuilder();
                indexBuilder.append("CREATE ");
                if (indexParam.getIndexType().equals("UNIQUE")){
                    indexBuilder.append("UNIQUE ");
                }
                indexBuilder.append("INDEX ");
                indexBuilder.append("PIESAT_DGDQ_").append(param.getTableName()).append("_").append(indexParam.getIndexName()).append(" on ");
                indexBuilder.append(param.getTableName()).append("(");
                StringBuilder columnName = new StringBuilder();
                for (String column:indexParam.getColumnList()) {
                    columnName.append(column);
                    columnName.append(",");
                }
                String columnNames = columnName.substring(0,columnName.length()-1);
                indexBuilder.append(columnNames).append(")");
                //索引创建
                dataManagementMapper.executeSql(indexBuilder.toString());
            }
        }
    }
}
